package com.example.jetpack;

import android.util.Log;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

public class UserViewModel extends BaseObservable {

    private UserEntity userEntity;

    public UserViewModel() {
        this.userEntity = new UserEntity();
        userEntity.setName("Jack");
    }

    @Bindable
    public String getUserName(){
        return userEntity.getName();
    }

    //userName值修改的话 会自动调用set方法
    public void setUserName(String userName){
        if(userName != null && !userName.equals(userEntity.getName())){
            Log.i("info",userName);
            userEntity.setName(userName);
            //修改完要进行通知
            notifyPropertyChanged(BR.userName);
        }
    }
}
